package com.scalar.forecast.projectSetup.actionCommands;

import com.scalar.forecast.actionCommands.ActionCommand;
import com.scalar.forecast.projectSetup.forms.ProjectSearchForm;
import com.scalar.forecast.commons.SessionKeys;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * This Action Command sets the page number to scope and directs to search page
 *
 * Created by Veeru. 
 * Date: Feb 17, 2005
 * Time: 6:11:49 PM 
 */

public class ProjectSearchDisplayPageCommand extends ActionCommand{

    public ActionForward execute( ActionMapping mapping,
                                      ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response ) {

        request.setAttribute( "showList", "true" );
        ActionForward actionForward = mapping.findForward( "projectSearch" );
        ProjectSearchForm projectSearchForm = ( ProjectSearchForm )form;
        HttpSession session = request.getSession();
        String pageNumber = request.getParameter( SessionKeys.REQUEST_PAGE_NUMBER );

        session.setAttribute( "columnMetaDataList", projectSearchForm.getColumnMetaDataList() );
        session.setAttribute( "projects", projectSearchForm.getProjectsList() );
        session.setAttribute( SessionKeys.REQUEST_TOTAL_RECS, projectSearchForm.getProjectsList().size()+"" );
        session.setAttribute( SessionKeys.REQUEST_PAGE_NUMBER, pageNumber );
        return actionForward;
    }

}
